Skip to content

Allow lazier configuration of jdks#19

Merged
CRogers merged 15 commits into
developfrom
callumr/allow-lazier-configuration
May 12, 2022
Merged

Allow lazier configuration of jdks#19
CRogers merged 15 commits into
developfrom
callumr/allow-lazier-configuration

Conversation

@CRogers
Copy link
Copy Markdown
Contributor

@CRogers CRogers commented May 5, 2022

Before this PR

When configuring an internal Gradle plugin to configure this plugin I ran into a problem - I couldn't work out which JDKs I had without doing an expensive network task - basically what @carterkozak warning me about in the baseline code.

After this PR

==COMMIT_MSG==
Allow lazy configuration of JDKs
==COMMIT_MSG==

Extra methods allow me to provide all the jdk configuration lazily when it is requested.

Possible downsides?

@CRogers CRogers requested a review from carterkozak May 5, 2022 13:29
@changelog-app
Copy link
Copy Markdown

changelog-app Bot commented May 5, 2022

Generate changelog in changelog/@unreleased

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Allow lazy configuration of JDKs

Check the box to generate changelog(s)

  • Generate changelog entry

import org.gradle.api.provider.Provider;
import org.gradle.api.provider.ProviderFactory;

final class DelayedConfigurableMap<K, V> {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to use some of the built in NamedDomainObjectCollection/MapProperty but they really did not seem to do exactly what I wanted - so I build my own thing here.

final class DelayedConfigurableMap<K, V> {
private final ProviderFactory providerFactory;
private final Supplier<V> valueFactory;
private final List<Provider<Map<K, Action<V>>>> configurations = new ArrayList<>();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

>>>> looks a lot like a merge conflict!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how you tell it's good code

import org.gradle.api.provider.Provider;
import org.gradle.api.provider.ProviderFactory;

final class DelayedConfigurableMap<K, V> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would it look like to abandon the map concept entirely, in favor of something shaped more like a function? I suspect this isn't the only place the map property may bite us

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree we should probably do that, started it here: palantir/gradle-baseline#2263

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated this PR to show what it would look like.

@CRogers CRogers merged commit 5904f1f into develop May 12, 2022
@svc-autorelease
Copy link
Copy Markdown
Collaborator

Released 0.4.0

@CRogers CRogers deleted the callumr/allow-lazier-configuration branch May 12, 2022 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants